<<<<<<< HEAD
import request from '@/utils/request'
=======
import request, { get, post, put } from '@/utils/request'
>>>>>>> c61637f (所有前后端正常登录)

// 获取订单列表
export function getOrders(params) {
  return request({
    url: '/orders',
    method: 'get',
    params
  })
}

// 获取订单详情
export function getOrderDetail(id) {
  return request({
    url: `/orders/${id}`,
    method: 'get'
  })
}

// 更新订单状态
export function updateOrderStatus(id, status, shippingInfo = null) {
  return request({
    url: `/orders/${id}/status`,
    method: 'put',
    data: {
      status,
      ...(shippingInfo && {
        logisticsCompany: shippingInfo.logisticsCompany,
        trackingNumber: shippingInfo.trackingNumber,
        remark: shippingInfo.remark
      })
    }
  })
}

// 取消订单
export function cancelOrder(id) {
  return request({
    url: `/orders/${id}/cancel`,
    method: 'put'
  })
}

// 发货
export function shipOrder(id, data) {
  return request({
    url: `/orders/${id}/ship`,
    method: 'put',
    data
  })
}

// 确认收货
export function confirmOrder(id) {
  return request({
    url: `/orders/${id}/confirm`,
    method: 'put'
  })
}

// 申请退款
export function refundOrder(id, data) {
  return request({
    url: `/orders/${id}/refund`,
    method: 'post',
    data
  })
}

// 获取订单统计
export function getOrderStats(params) {
  return request({
    url: '/orders/stats',
    method: 'get',
    params
  })
<<<<<<< HEAD
=======
}

// 获取今日订单
export function getTodayOrders() {
  return get('/orders/today', {}, {
    showLoading: false
  })
}

// 获取订单列表（新版本）
export function getOrdersList(params = {}) {
  return get('/orders', params, {
    showLoading: false
  })
}

// 洗护订单状态枚举映射
export const ORDER_STATUS = {
  PENDING: 'PENDING',           // 待接单
  ACCEPTED: 'ACCEPTED',         // 已接单
  PAID: 'PAID',                 // 已付款
  PICKUP_STARTED: 'PICKUP_STARTED',     // 开始取件
  PICKUP_COMPLETED: 'PICKUP_COMPLETED', // 取件完成
  PROCESSING: 'PROCESSING',     // 洗护中
  QUALITY_CHECK: 'QUALITY_CHECK', // 质检中
  DELIVERY_STARTED: 'DELIVERY_STARTED', // 开始配送
  DELIVERED: 'DELIVERED',       // 已送达
  COMPLETED: 'COMPLETED',       // 已完成
  CANCELLED: 'CANCELLED',       // 已取消
  REFUNDED: 'REFUNDED'          // 已退款
}

// 洗护订单状态文本映射
export const ORDER_STATUS_TEXT = {
  [ORDER_STATUS.PENDING]: '待接单',
  [ORDER_STATUS.ACCEPTED]: '已接单',
  [ORDER_STATUS.PAID]: '已付款',
  [ORDER_STATUS.PICKUP_STARTED]: '开始取件',
  [ORDER_STATUS.PICKUP_COMPLETED]: '取件完成',
  [ORDER_STATUS.PROCESSING]: '洗护中',
  [ORDER_STATUS.QUALITY_CHECK]: '质检中',
  [ORDER_STATUS.DELIVERY_STARTED]: '开始配送',
  [ORDER_STATUS.DELIVERED]: '已送达',
  [ORDER_STATUS.COMPLETED]: '已完成',
  [ORDER_STATUS.CANCELLED]: '已取消',
  [ORDER_STATUS.REFUNDED]: '已退款'
}

// 洗护订单状态颜色映射
export const ORDER_STATUS_COLOR = {
  [ORDER_STATUS.PENDING]: 'warning',
  [ORDER_STATUS.ACCEPTED]: 'primary',
  [ORDER_STATUS.PAID]: 'success',
  [ORDER_STATUS.PICKUP_STARTED]: 'primary',
  [ORDER_STATUS.PICKUP_COMPLETED]: 'success',
  [ORDER_STATUS.PROCESSING]: 'primary',
  [ORDER_STATUS.QUALITY_CHECK]: 'info',
  [ORDER_STATUS.DELIVERY_STARTED]: 'primary',
  [ORDER_STATUS.DELIVERED]: 'success',
  [ORDER_STATUS.COMPLETED]: 'success',
  [ORDER_STATUS.CANCELLED]: 'danger',
  [ORDER_STATUS.REFUNDED]: 'info'
}

// 批量更新订单状态
export function batchUpdateOrderStatus(orderIds, status, data = {}) {
  return put('/orders/batch/status', {
    orderIds,
    status,
    ...data
  })
}

// 批量取消订单
export function batchCancelOrders(orderIds, reason) {
  return put('/orders/batch/cancel', {
    orderIds,
    reason
  })
}

// 导出订单数据
export function exportOrdersData(params = {}) {
  return get('/orders/export', params, {
    responseType: 'blob'
  })
}

// 获取订单时间线
export function getOrderTimeline(orderId) {
  return get(`/orders/${orderId}/timeline`)
}

// 获取订单物流信息
export function getOrderLogistics(orderId) {
  return get(`/orders/${orderId}/logistics`)
}

// 更新订单备注
export function updateOrderRemark(orderId, remark) {
  return put(`/orders/${orderId}/remark`, { remark })
}

// 获取订单评价
export function getOrderReview(orderId) {
  return get(`/orders/${orderId}/review`)
}

// 回复订单评价
export function replyOrderReview(orderId, reply) {
  return post(`/orders/${orderId}/review/reply`, { reply })
}

// 获取订单分析数据
export function getOrderAnalysis(params = {}) {
  return get('/orders/analysis', params)
}

// 获取订单趋势数据
export function getOrderTrends(params = {}) {
  return get('/orders/trends', params)
}

// 搜索订单
export function searchOrders(keyword, filters = {}) {
  return get('/orders/search', {
    keyword,
    ...filters
  })
}

// 获取急需处理的订单
export function getUrgentOrders() {
  return get('/orders/urgent')
}

// 获取订单配置
export function getOrderConfig() {
  return get('/orders/config')
}

// 更新订单配置
export function updateOrderConfig(config) {
  return put('/orders/config', config)
}

// 获取订单模板
export function getOrderTemplates() {
  return get('/orders/templates')
}

// 创建订单模板
export function createOrderTemplate(template) {
  return post('/orders/templates', template)
}

// 获取客户订单历史
export function getCustomerOrderHistory(customerId, params = {}) {
  return get(`/customers/${customerId}/orders`, params)
}

// 获取服务订单统计
export function getServiceOrderStats(serviceId, params = {}) {
  return get(`/services/${serviceId}/orders/stats`, params)
}

// 洗护订单状态流转规则
export const ORDER_STATUS_FLOW = {
  [ORDER_STATUS.PENDING]: [ORDER_STATUS.ACCEPTED, ORDER_STATUS.CANCELLED],
  [ORDER_STATUS.ACCEPTED]: [ORDER_STATUS.PAID, ORDER_STATUS.CANCELLED],
  [ORDER_STATUS.PAID]: [ORDER_STATUS.PICKUP_STARTED, ORDER_STATUS.CANCELLED, ORDER_STATUS.REFUNDED],
  [ORDER_STATUS.PICKUP_STARTED]: [ORDER_STATUS.PICKUP_COMPLETED, ORDER_STATUS.CANCELLED],
  [ORDER_STATUS.PICKUP_COMPLETED]: [ORDER_STATUS.PROCESSING, ORDER_STATUS.CANCELLED],
  [ORDER_STATUS.PROCESSING]: [ORDER_STATUS.QUALITY_CHECK, ORDER_STATUS.DELIVERY_STARTED],
  [ORDER_STATUS.QUALITY_CHECK]: [ORDER_STATUS.DELIVERY_STARTED, ORDER_STATUS.PROCESSING],
  [ORDER_STATUS.DELIVERY_STARTED]: [ORDER_STATUS.DELIVERED],
  [ORDER_STATUS.DELIVERED]: [ORDER_STATUS.COMPLETED, ORDER_STATUS.REFUNDED],
  [ORDER_STATUS.COMPLETED]: [ORDER_STATUS.REFUNDED],
  [ORDER_STATUS.CANCELLED]: [],
  [ORDER_STATUS.REFUNDED]: []
}

// 检查状态是否可以流转
export function canTransitionTo(currentStatus, targetStatus) {
  return ORDER_STATUS_FLOW[currentStatus]?.includes(targetStatus) || false
}

// 获取可流转的状态列表
export function getAvailableTransitions(currentStatus) {
  return ORDER_STATUS_FLOW[currentStatus] || []
}

// ==================== 洗护系统特有API ====================

// 接受订单
export function acceptOrder(orderId, data = {}) {
  return post(`/orders/${orderId}/accept`, data)
}

// 拒绝订单
export function rejectOrder(orderId, data) {
  return post(`/orders/${orderId}/reject`, data)
}

// 确认付款
export function confirmPayment(orderId, data = {}) {
  return post(`/orders/${orderId}/confirm-payment`, data)
}

// 开始取件
export function startPickup(orderId, data = {}) {
  return post(`/orders/${orderId}/start-pickup`, data)
}

// 确认取件
export function confirmPickup(orderId, data = {}) {
  return post(`/orders/${orderId}/confirm-pickup`, data)
}

// 开始洗护
export function startProcessing(orderId, data = {}) {
  return post(`/orders/${orderId}/start-processing`, data)
}

// 完成洗护
export function completeProcessing(orderId, data = {}) {
  return post(`/orders/${orderId}/complete-processing`, data)
}

// 开始质检
export function startQualityCheck(orderId, data = {}) {
  return post(`/orders/${orderId}/start-quality-check`, data)
}

// 完成质检
export function completeQualityCheck(orderId, data = {}) {
  return post(`/orders/${orderId}/complete-quality-check`, data)
}

// 开始配送
export function startDelivery(orderId, data = {}) {
  return post(`/orders/${orderId}/start-delivery`, data)
}

// 确认送达
export function confirmDelivery(orderId, data = {}) {
  return post(`/orders/${orderId}/confirm-delivery`, data)
}

// 完成订单
export function completeOrder(orderId, data = {}) {
  return post(`/orders/${orderId}/complete`, data)
}

// 申请退款
export function requestRefund(orderId, data) {
  return post(`/orders/${orderId}/refund`, data)
}

// 上传订单照片
export function uploadOrderPhotos(orderId, data) {
  return post(`/orders/${orderId}/photos`, data)
}

// 获取订单照片
export function getOrderPhotos(orderId) {
  return get(`/orders/${orderId}/photos`)
}

// 获取附近订单
export function getNearbyOrders(params = {}) {
  return get('/orders/nearby', params)
}

// 服务类型常量
export const SERVICE_TYPES = {
  LAUNDRY: 'LAUNDRY',           // 衣物洗护
  SHOES: 'SHOES',               // 鞋类护理
  BAGS: 'BAGS',                 // 包包清洗
  BEDDING: 'BEDDING',           // 床品清洗
  PETS: 'PETS',                 // 宠物洗护
  CAR_WASH: 'CAR_WASH',         // 汽车清洗
  HOME_CLEANING: 'HOME_CLEANING', // 家庭清洁
  PLUMBING: 'PLUMBING'          // 管道疏通
}

export const SERVICE_TYPE_TEXT = {
  [SERVICE_TYPES.LAUNDRY]: '衣物洗护',
  [SERVICE_TYPES.SHOES]: '鞋类护理',
  [SERVICE_TYPES.BAGS]: '包包清洗',
  [SERVICE_TYPES.BEDDING]: '床品清洗',
  [SERVICE_TYPES.PETS]: '宠物洗护',
  [SERVICE_TYPES.CAR_WASH]: '汽车清洗',
  [SERVICE_TYPES.HOME_CLEANING]: '家庭清洁',
  [SERVICE_TYPES.PLUMBING]: '管道疏通'
}

export const SERVICE_TYPE_COLOR = {
  [SERVICE_TYPES.LAUNDRY]: 'primary',
  [SERVICE_TYPES.SHOES]: 'success',
  [SERVICE_TYPES.BAGS]: 'warning',
  [SERVICE_TYPES.BEDDING]: 'info',
  [SERVICE_TYPES.PETS]: 'danger',
  [SERVICE_TYPES.CAR_WASH]: 'primary',
  [SERVICE_TYPES.HOME_CLEANING]: 'success',
  [SERVICE_TYPES.PLUMBING]: 'warning'
>>>>>>> c61637f (所有前后端正常登录)
}